  
	<#include
        "../../common/com.html"  /> <@layout>
<head>
    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="${ctx}/static/assets/css/ui.jqgrid.css" />
    <!-- ace styles -->
    <script src="${ctx}/static/inc/platform/js/ajax.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/cbb/artDialog/skins/blue.css">
    <script src="${ctx}/static/cbb/artDialog/jquery.artDialog.js"></script>
  <link href='${ctx}/static/assets/css/select2.css' media='all' rel='stylesheet' type='text/css'/>
<script src='${ctx}/static/assets/js/select2.min.js' type='text/javascript'></script>
<script src='${ctx}/static/assets/js/select2_locale_zh-CN.js' type='text/javascript'></script>
</head>
    <script type="text/javascript">
    //open new window
    function newModels(){
        var url = '${ctx}/cpglRk/newModes' ;
        initArtDialog({url:url, title:'新增', width:650, height:450,lock:true,background: '#EAEAEA'});
    }

  /**
     * 删除选中的模型信息
     */
    function dels(obj,wpid,wpsl){
            var url = '${ctx}/cpglRk/delete/';
            $("#id").attr("value",obj);
            $("#wpid").attr("value",wpid);
            $("#wpsl").attr("value",wpsl);
            $('#myform').form('submit', {
                url : url,
                onSubmit : function() {
                },
                success : function(data) {
                    // 回填页面
                    alert(data);
                    window.location.reload();
                }
            });
    }

</script>
<body>

<div class="page-content">
    
	 <div class="row-fluid">
        <div class="span12">
            <form class="form-inline" id="myform">
                <input type="hidden" name="id" id="id">
                   <input type="hidden" name="wpids" id="wpids">
                                 <input type="hidden" name="wpsl" id="wpsl">
                        日期起：<input type="text"  name="search_EQ_start" id="start"   class="query"  style="min-height: 24px;width: 100px"   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'end\')}'})"      />
                日期止：<input type="text"  name="end" id="end"   class="query"  style="min-height: 24px;width: 100px" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'start\')}'})" />
					
						商品名称<input id="wpid" name="wpid" type="text" style="min-height: 24px;width:210px" />
							          
                <button id="search_btn" onclick="return false;" class="btn btn-info btn-small"  onclick="queryModel()">
                    查询
                </button>

            </form>
            <!-- PAGE CONTENT BEGINS -->
            <table id="grid-table"></table>
            <div id="grid-pager"></div>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.span -->
    </div><!-- /.row-fluid -->
</div><!-- /.page-content -->
<!-- page specific plugin scripts -->


<#include  "../../common/end.html"  /> 
<script>
    function add(){
        var url = '${ctx}/cpglRk/newModes' ;
        window.location.href=url;
        //initArtDialog({url:url, title:'新增', width:600, height:400,lock:true,background: '#EAEAEA'});
    }
    /**
     * 编辑选中的模型信息
     */
    function edits(obj){
    	var rowData = $("#grid-table").jqGrid('getGridParam','selarrrow');
    	if(rowData.length ==1){
    	    var id= jQuery('#grid-table').jqGrid('getCell',rowData[0],'id');//name是
    	    var  url = '${ctx}/cpglRk/removeModes?id=' + id;
          //  window.location.href=url;
              initArtDialog({url:url, title:'退货', width:530, height:330,lock:true,background: '#EAEAEA'});
	    	} else {
	    		alert("请选中一行进货单据进行退货处理！");
	    	}
 	//       var rowData = $("#grid-table").getRowData(obj);
     //   initArtDialog({url:url, title:'修改', width:730, height:330,lock:true,background: '#EAEAEA'});
    }
</script>
<script type="text/javascript">

$("#search_btn").click(function(){
	  var start=$("#start").val();
      var end=$("#end").val();
      var wpid=$("#wpid").val();
   // var start=$("#start").val();

    $("#grid-table").jqGrid('setGridParam',{
        datatype:'json',
        postData:{  'search_GTE_lrrq':start,'search_LTE_lrrq':end,'search_EQ_wpid':wpid}, //发送数据 'search_LIKE_lrrq':start
        page:1
    }).trigger("reloadGrid"); //重新载入
});


jQuery(function($) {

    //  jqgrid
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";
    var start=$("#start").val();

    jQuery(grid_selector).jqGrid({
        datatype: "json", //将这里改为使用JSON数据
        mtype:"POST",
        postData:{}, //发送数据
        url:'${ctx}/cpglRk/query',
        height: '55%',
        footerrow:false,  //合计数据
        colNames:[ 
        	    '商品名称',  '建议售价',  '长途运费',  '短途运费',  '商品数量', '总价', '进货厂家',  '电话',     '录入人',  '录入日期', '','',''],
        colModel:[
    //        {name:'edits',index:'',width:80,sortable:false, resizable:true,formatter: printthis},
					    {name:'wpmc', width:100,sortable:false},
					    {name:'jysj', width:100,sortable:false},
					    {name:'ctyf', width:100,sortable:false},
					    {name:'dtyf', width:100,sortable:false},
					    {name:'wpsl', width:100,sortable:false},
					    {name:'jhjg', width:100,sortable:false},
					    {name:'jhcj', width:100,sortable:false},
					    {name:'cjdh', width:100,sortable:false},
					    {name:'lrrmc', width:100,sortable:false},
					    {name:'lrrq', width:100,sortable:false},
					    {name:'id', width:100,sortable:false,hidden:true},
					    {name:'wpid', width:100,sortable:false,hidden:true},
					    {name:'id', width:100,sortable:false,hidden:true}

        ],
        rownumbers:true,//添加左侧行号
        sortname: 'id',
        sortable: false,
        viewrecords: true, //是否显示行数
        rowNum:20,
        rowList:[10,20,30],
        loadtext: '正在加载数据...',
        loadui : 'block',
        pager : pager_selector,
        altRows: true,
        shrinkToFit: true,
        //toppager: true,
//
       multiselect: true,
       multikey: "id",
       multiboxonly: true,

       loadComplete : function() {
            var table = this;
            setTimeout(function(){
                updatePagerIcons(table);
            },
                    0);
        } ,
  //      ondblClickRow: openview,
//
        caption: " <input type='button' onclick='add()'  class='btn btn-mini btn-warning' value='新增'>&nbsp;&nbsp; "+
        	"<input type='button' onclick='edits()'  class='btn btn-mini btn-danger' value='退货'>" ,
        autowidth: true
    });
        //按钮
        function printthis(cellvalue,options,rowObject){
            var ids=rowObject.id;
            var wpid =rowObject.wpid;
            var wpsl =rowObject.wpsl;

            var buttomHtml= "<a class='green' href=\"javascript:edits('" + ids+"')\" title='修改'><i class='icon-pencil bigger-130'></i></a> &nbsp;&nbsp;" +
                    "<a class='red' href=\"javascript:dels('" + ids + "','" + wpid + "','" + wpsl + "')\" title='删除'><i class='icon-trash  bigger-130'></i></a> </div> ";

//            var buttomHtml="<a href='#' class='btn btn-primary btn-mini ' onclick='opennew()'><i class='icon-print  bigger-125  '>打印</i>  </a>";
            return buttomHtml
        }


        function  openview(rowid,iRow,iCol,e){
            url = '${ctx}/cpglRk/view?id=' + rowid;
            initArtDialog({url:url, title:'查看', width:500, height:280,lock:true,background: '#EAEAEA'});
        }
        
    });

  
  
    
    //replace icons with FontAwesome icons like above
    function updatePagerIcons(table) {
        var replacement =
        {
            'ui-icon-seek-first' : 'icon-double-angle-left bigger-150',
            'ui-icon-seek-prev' : 'icon-angle-left bigger-150',
            'ui-icon-seek-next' : 'icon-angle-right bigger-150',
            'ui-icon-seek-end' : 'icon-double-angle-right bigger-150'
        };
        $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
            var icon = $(this);
            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

            if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
        })
    }

    function enableTooltips(table) {
        $('.navtable .ui-pg-button').tooltip({container:'body'});
        $(table).find('.ui-pg-div').tooltip({container:'body'});
    }

    //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

//    $( "#adds" ).on('click', function(e) {
//        e.preventDefault();
//        addr();
//    });



window.onresize = function  _doResize() {
    var ss = pageSize();
    $("#grid-table").jqGrid('setGridWidth', ss.WinW-10).jqGrid('setGridHeight', ss.WinH-200);
}

function pageSize() {
    var winW, winH;
    if(window.innerHeight) {// all except IE
        winW = window.innerWidth;
        winH = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;
    } else if (document.body) { // other
        winW = document.body.clientWidth;
        winH = document.body.clientHeight;
    }  // for small pages with total size less then the viewport
    return {WinW:winW, WinH:winH};
}

//select2查询列表每次只查数据的前20条

//select2查询列表每次只查数据的前20条
 $('#wpid').select2({
	        placeholder: "请输入查询商品名称或者编号",
	        minimumInputLength: 0,
	        ajax: {
	            url: "${ctx}/cgglWp/getWpxx",
	            dataType: 'json',
	            data: function (term, page) {
	                return {
	                    term: term,
	                    page_limit: 20,
	                    page: 0,
	                    apikey: "getwpxx"
	                };
	            },
	            results: function (data, page) {
	                return { results: data};
	            }

	        }
	    });

</script>

</body>
 </@layout> 
